<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" href="../css/sign_in.css">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div class="signIn" id="app">

    <table border="0" class="formtable">
        <tr>
            <td>
                <p><span class="title">图书销售管理系统</span></p>
            </td>
        </tr>
        <tr>
            <td>
                <el-input v-model="userInfo.userName" placeholder="请输入用户名"></el-input>
            </td>
        </tr>
        <tr>
            <td>
                <el-input placeholder="请输入密码" v-model="userInfo.password" show-password></el-input>
            </td>
        </tr>
        <tr>
            <td>
                <el-button type="primary" @click="signIn">登录</el-button>
            </td>
        </tr>
    </table>
</div>


<script src="../js/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            userInfo: {
                userName: '',
                password: '',
            },
            serviceState: {
                flag: '',
                msg: '',
                ps:''
            }
        },
        methods: {
            signIn(){
              axios.post("/signIn",this.userInfo).then(
                  res=>{
                      console.log(res)
                      this.serviceState.flag = res.data.flag;
                      this.serviceState.msg = res.data.msg;
                      this.serviceState.ps = res.data.ps;
                      if(this.serviceState.flag==1) {
                          alert(this.serviceState.msg);
                          if(this.serviceState.ps == "admin") {
                              //跳转至管理员面板
                              location.replace("admin.html");
                          }
                          else if (this.serviceState.ps == "customer") {
                              //携带userName跳转至顾客面板
                              location.replace("customer.html");
                              //设置sessionStorage
                              window.sessionStorage.setItem('userName', this.userName);
                          }
                      }
                      else {
                          alert(this.serviceState.msg);
                      }
                  }
              )
            },
            test: function () {
                axios.post("/test", "")
                    .then(resp => {
                    })
            }
        }
    });
</script>
</body>
</html>